/*
 * Copyright (C) 2020 Baidu, Inc. All Rights Reserved.
 */
package com.wty.basic.errordemo;

import com.google.common.hash.BloomFilter;
import com.google.common.hash.Funnels;
import org.junit.Test;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.IntStream;

/**
 * @Author wangtengyu
 * @Date 2020/7/29 5:15 下午
 * @Description
 */
public class BloomFilterDemo {


    @Test
    public void test() {
        AtomicInteger count = new AtomicInteger(0);
        BloomFilter bloomFilter = BloomFilter.create(Funnels.integerFunnel(), 10000, 0.01);
        IntStream.rangeClosed(0, 10000).forEach(i -> bloomFilter.put(i));

        IntStream.rangeClosed(10001, 20000).forEach(item -> {
            if (!bloomFilter.mightContain(item)) {
                count.getAndIncrement();
                System.out.println(item + "误判了");
            }
        });
        System.out.println("误判的个数" + count.get());


    }
}
